<template>
  <div class="p-2">
    <!--查询区域-->
    <div class="jeecg-basic-table-form-container">
      <a-form ref="formRef" @keyup.enter.native="reload" :model="queryParam" :label-col="labelCol" :wrapper-col="wrapperCol">
        <a-row :gutter="24">
          <a-col :lg="6">
            <a-form-item name="supplier">
              <template #label><span title="所属公司">所属公司</span></template>
              <j-dict-select-tag placeholder="请选择所属公司" v-model:value="queryParam.supplier" dictCode="tm_supplier_manage,supplier_name,id" allowClear/>
            </a-form-item>
          </a-col>
          <a-col :lg="6">
            <a-form-item name="realName">
              <template #label><span title="姓名">姓名</span></template>
              <a-input placeholder="请输入姓名" v-model:value="queryParam.realName" allowClear></a-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :lg="6">
              <a-form-item name="jender">
                <template #label><span title="性别">性别</span></template>
                <j-dict-select-tag placeholder="请选择性别" v-model:value="queryParam.jender" dictCode="sex" allowClear/>
              </a-form-item>
            </a-col>
            <!-- <a-col :lg="6">
              <a-form-item name="email">
                <template #label><span title="邮箱">邮箱</span></template>
                <a-input placeholder="请输入邮箱" v-model:value="queryParam.email"></a-input>
              </a-form-item>
            </a-col> -->
            <!-- <a-col :lg="6">
              <a-form-item name="birthday">
                <template #label><span title="出生日期">出生日期</span></template>
                <a-date-picker valueFormat="YYYY-MM-DD" placeholder="请选择出生日期" v-model:value="queryParam.birthday" />
              </a-form-item>
            </a-col> -->
            <a-col :lg="6">
              <a-form-item name="education">
                <template #label><span title="学历">学历</span></template>
                <j-dict-select-tag placeholder="请选择学历" v-model:value="queryParam.education" dictCode="education" allowClear/>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="major">
                <template #label><span title="专业">专业</span></template>
                <a-input placeholder="请输入专业" v-model:value="queryParam.major" allowClear></a-input>
              </a-form-item>
            </a-col>
            <!-- <a-col :lg="6">
              <a-form-item name="skill">
                <template #label><span title="技能项">技能项</span></template>
                <j-select-multiple placeholder="请选择技能项" dictCode="skill_list" v-model:value="queryParam.skill" />
              </a-form-item>
            </a-col> -->
            <a-col :lg="6">
              <a-form-item name="filterStatus">
                <template #label><span title="筛选状态">筛选状态</span></template>
                <j-dict-select-tag placeholder="请选择筛选状态" v-model:value="queryParam.filterStatus" dictCode="filter_status" allowClear/>
              </a-form-item>
            </a-col>
           <a-col :lg="6">
             <a-form-item name="resumeStatus">
               <template #label><span title="简历状态">简历状态</span></template>
               <j-dict-select-tag placeholder="请选择简历状态" v-model:value="queryParam.resumeStatus" dictCode="resume_status"/>
           </a-form-item>
          </a-col>
          <!--  </a-col>
            <a-col :lg="6">
              <a-form-item name="entryStatus">
                <template #label><span title="入场状态">入场状态</span></template>
                <j-dict-select-tag placeholder="请选择入场状态" v-model:value="queryParam.entryStatus" dictCode="entry_status" allowClear/>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="lockStatus">
                <template #label><span title="锁定状态">锁定状态</span></template>
                <j-dict-select-tag placeholder="请输入锁定状态" v-model:value="queryParam.lockStatus" dictCode="lock_status" allowClear></j-dict-select-tag>
              </a-form-item>
            </a-col>
          <a-col :lg="6">
              <a-form-item name="lockBy">
                <template #label><span title="锁定人">锁定人</span></template>
                <a-input placeholder="请输入锁定人" v-model:value="queryParam.lockBy"></a-input>
              </a-form-item>
            </a-col> 
             <a-col :lg="6">
              <a-form-item name="createBy">
                <template #label><span title="创建人">创建人</span></template>
                <a-input placeholder="请输入创建人" v-model:value="queryParam.createBy"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="createTime">
                <template #label><span title="创建日期">创建日期</span></template>
                <a-date-picker showTime valueFormat="YYYY-MM-DD HH:mm:ss" placeholder="请选择创建日期" v-model:value="queryParam.createTime" />
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="updateBy">
                <template #label><span title="更新人">更新人</span></template>
                <a-input placeholder="请输入更新人" v-model:value="queryParam.updateBy"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="updateTime">
                <template #label><span title="更新日期">更新日期</span></template>
                <a-date-picker showTime valueFormat="YYYY-MM-DD HH:mm:ss" placeholder="请选择更新日期" v-model:value="queryParam.updateTime" />
              </a-form-item>
            </a-col> -->
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-col :lg="6">
                <a-button type="primary" preIcon="ant-design:search-outlined" @click="reload">查询</a-button>
                <a-button preIcon="ant-design:reload-outlined" @click="searchReset" style="margin-left: 8px">重置</a-button>
                <a @click="toggleSearchStatus = !toggleSearchStatus" style="margin-left: 8px">
                  {{ toggleSearchStatus ? '收起' : '展开' }}
                  <Icon :icon="toggleSearchStatus ? 'ant-design:up-outlined' : 'ant-design:down-outlined'" />
                </a>
              </a-col>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!--引用表格-->
   <BasicTable @register="registerTable" :rowSelection="rowSelection" @row-dbClick="rowDbClick">
     <!--插槽:table标题-->
      <template #tableTitle>
          <a-button type="primary" @click="handleAdd" preIcon="ant-design:plus-outlined"> 新增</a-button>
          <a-button  type="primary" preIcon="ant-design:export-outlined" @click="onExportXls"> 导出</a-button>
          <!-- <a-button preIcon="ant-design:import-outlined" type="primary" @click="openModal(true)">弹窗导入</a-button> -->
          <JImportModal @register="registerModal" :url="getImportUrl" online/>

          <!-- <j-upload v-model="fileList" text="上传"></j-upload> -->
          
          <!-- <j-upload-button  type="primary" preIcon="ant-design:import-outlined" @click="onImportXls" multiple="true">导入2</j-upload-button> -->
          <!-- <a-dropdown v-if="selectedRowKeys.length > 0">
              <template #overlay>
                <a-menu>
                  <a-menu-item key="1" @click="batchHandleDelete">
                    <Icon icon="ant-design:delete-outlined"></Icon>
                    删除
                  </a-menu-item>
                </a-menu>
              </template>
              <a-button>批量操作
                <Icon icon="mdi:chevron-down"></Icon>
              </a-button>
        </a-dropdown> -->
        <!-- 高级查询 -->
        <!-- <super-query :config="superQueryConfig" @search="handleSuperQuery" /> -->
      </template>
       <!--操作栏-->
      <template #action="{ record }">
        <TableAction :actions="getTableAction(record)" :dropDownActions="getDropDownAction(record)"/>
      </template>
      <!--字段回显插槽-->
      <template v-slot:bodyCell="{ column, record, index, text }">
        <template v-if="column.dataIndex==='resumeFile'">
          <!--文件字段回显插槽-->
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button v-else :ghost="true" type="primary" preIcon="ant-design:download-outlined" size="small" @click="downloadFile(text)">下载</a-button>
        </template>
        <template v-if="column.dataIndex==='resumeContent'">
          <!--富文本件字段回显插槽-->
          <div v-html="text"></div>
        </template>
      </template>
    </BasicTable>
    <!-- 锁定表单区域 -->
    <ResumeLockRecordModal ref="regResumeLockModal" @success="handleSuccess"></ResumeLockRecordModal>
     <!-- 表单区域 -->
    <ResumeAssignModal ref="regResumeAssignModal" @success="handleSuccess"></ResumeAssignModal>
    <!-- 表单区域 -->
    <!-- <ResumeModal @register="registerModal" @success="handleSuccess"></ResumeModal> -->
    <!-- 面评 -->
    <ResumeEvaluateModal ref="registerEvaluateModal" @success="handleSuccess"></ResumeEvaluateModal>
    <!-- 入项 -->
    <OutsourcePersonAccountModal ref="registerOutsourcePersonAccountModal" @success="handleSuccess"></OutsourcePersonAccountModal>
    <!-- 抽屉 -->
    <ResumeDrawer @register="registerDrawer" @success="handleSuccess" :showFooter="showFooter"></ResumeDrawer>

    <ResumeLockPostionReqDrawer @register="registerLockPostionReqDrawer" @success="handleSuccess" :showFooter="showFooter"></ResumeLockPostionReqDrawer>
    
  </div>
</template>

<script lang="ts" name="tm-resume" setup>
  import {ref, reactive, computed, unref} from 'vue';
  import JImportModal from '/@/components/Form/src/jeecg/components/JImportModal.vue';

  import {BasicTable, useTable, TableAction} from '/@/components/Table';
  import { useListPage } from '/@/hooks/system/useListPage'
  import {useModal} from '/@/components/Modal';
  import ResumeModal from './components/ResumeModal.vue'
  import ResumeDrawer from './components/ResumeDrawer.vue'
  import ResumeLockPostionReqDrawer from './components/ResumeLockPostionReqDrawer.vue'
  import {columns, searchFormSchema, superQuerySchema} from './Resume.data';
  import { operatorFilter,list, deleteOne, batchDelete, getImportUrl,getExportUrl} from './Resume.api';
  import {downloadFile} from '/@/utils/common/renderUtils';
  import JDictSelectTag from '/@/components/Form/src/jeecg/components/JDictSelectTag.vue';
  import JSelectMultiple from '/@/components/Form/src/jeecg/components/JSelectMultiple.vue';
  import { useUserStore } from '/@/store/modules/user';
  import ResumeAssignModal from "@/views/tm/resumeAssign/components/ResumeAssignModal.vue";
  import ResumeEvaluateModal from "@/views/tm/resumeEvaluate/components/ResumeEvaluateModal.vue";
  import OutsourcePersonAccountModal
    from "@/views/tm/outsourcePersonAccount/components/OutsourcePersonAccountModal.vue";
  import ResumeLockRecordModal
  from "@/views/tm/resumeLockRecord/components/ResumeLockRecordModal.vue";
  import ResumeAssignForm from "@/views/tm/resumeAssign/components/ResumeAssignForm.vue";
  //import {ResumeEvaluateModal} from '/@views/tm/resumeEvaluate/components/ResumeEvaluateModal.vue';
  //import {OutsourcePersonAccountModal} from '/@views/tm/outsourcePersonAccount.bak/components/OutsourcePersonAccountModal.vue';
  import {useDrawer} from "@/components/Drawer";
  import JInput from '/@/components/Form/src/jeecg/components/JInput.vue';
  import { json } from 'stream/consumers';
  import { useMessage } from '/@/hooks/web/useMessage';

  const showFooter = ref(true);
  const formRef = ref();
  const queryParam = reactive<any>({});
  const checkedKeys = ref<Array<string | number>>([]);
  const { createMessage } = useMessage();

  //注册model
  const [registerModal, {openModal}] = useModal();
  // const [registerModal, {openModal}] = useModal();
  const [registerDrawer, { openDrawer }] = useDrawer();
  const [registerLockPostionReqDrawer, { openDrawer: openLockPostionReqDrawer }] = useDrawer();
  const userStore = useUserStore();
  const regResumeAssignModal = ref();
  const regResumeLockModal = ref();
  const registerEvaluateModal = ref();
  const registerOutsourcePersonAccountModal = ref();
   //注册table数据
  const { prefixCls,tableContext,onExportXls,onImportXls } = useListPage({
      tableProps:{
           title: '简历',
           api: list,
           columns,
           canResize:false,
           useSearchForm: false,
           actionColumn: {
               width: 255,
               fixed:'right'
           },
           beforeFetch: (params) => {
             return Object.assign(params, queryParam);
           },
        },
        exportConfig: {
            name:"简历",
            url: getExportUrl,
            params: queryParam,
        },
        importConfig: {
            url: getImportUrl,
            success: handleSuccess
        },
    })

  const [registerTable, {reload},{ rowSelection, selectedRowKeys }] = tableContext

  // 高级查询配置
  const superQueryConfig = reactive(superQuerySchema);

  /**
   * 高级查询事件
   */
  function handleSuperQuery(params) {
    Object.keys(params).map((k) => {
      queryParam[k] = params[k];
    });
    reload();
  }
  function showLockPostionReq(record: Recordable) {
      showFooter.value = false;
      openLockPostionReqDrawer(true, {
       record,
       disableSubmit:true,
       isUpdate: true,
       showFooter: false,
     });
  }
   /**
    * 新增事件
    */
  function handleAdd() {
     // openModal(true, {
     //   isUpdate: false,
     //   showFooter: true,
     // });
     showFooter.value = true;
     openDrawer(true, {
       disableSubmit:false,
       isUpdate: false,
       showFooter: true,
     });
  }
   /**
    * 编辑事件
    */
  function handleEdit(record: Recordable) {
     // openModal(true, {
     //   record,
     //   isUpdate: true,
     //   showFooter: true,
     // });
     showFooter.value = true;
     openDrawer(true, {
       record,
       disableSubmit:false,
       isUpdate: true,
       showFooter: true,
     });
   }
  function rowDbClick(record, index, event) {
    handleDetail(record);
  }
   /**
    * 详情
   */
  function handleDetail(record: Recordable) {
     // openModal(true, {
     //   record,
     //   isUpdate: true,
     //   showFooter: false,
     // });
     showFooter.value = false;
     openDrawer(true, {
       record,
       disableSubmit:true,
       isUpdate: true,
       showFooter: false,
     });
   }
  /**
   * 分配锁定
   */
  function handleResumeLock(record: Recordable) {
    // regResumeAssignModal.value.disableSubmit = false;
    // regResumeAssignModal.value.personAssign(record);
    regResumeLockModal.value.disableSubmit = false;
    regResumeLockModal.value.resumeLock(record);
    
  }
  /**
   * 入项
   */
  function handlePersonEntry(record: Recordable) {
    if(record.entryStatus === '1') {
      createMessage.warning('人员已入项');
    } else {
      registerOutsourcePersonAccountModal.value.disableSubmit = false;
      registerOutsourcePersonAccountModal.value.personEntry(record);
    }

  }

  function handleResumePass(record: Recordable) {
    let params = {
      resumeId:record.id,
      filterStatus: 1
    }
    operatorFilter(params).then((res)=>{
      reload();
    })
  }

  function handleResumeFail(record: Recordable) {
    let params = {
      resumeId:record.id,
      filterStatus: 2
    }
    operatorFilter(params).then((res)=>{
      reload();
    })
    
  }
  /**
   * 面试评价
   */
  function handleResumeEvaluate(record: Recordable) {
    // console.log(registerEvaluateModal.value)
    registerEvaluateModal.value.disableSubmit = false;
    registerEvaluateModal.value.addResumeEvaluate(record);
    // registerModal.value.disableSubmit = false;
    // registerModal.value.add();
  }
   /**
    * 删除事件
    */
  async function handleDelete(record) {
     await deleteOne({id: record.id}, handleSuccess);
   }
   /**
    * 批量删除事件
    */
  async function batchHandleDelete() {
     await batchDelete({ids: selectedRowKeys.value},handleSuccess);
   }
   /**
    * 成功回调
    */
  function handleSuccess() {
      (selectedRowKeys.value = []) && reload();
   }
   /**
      * 操作栏
      */
  function getTableAction(record){
       return [
         {
           label: '锁定',
           //筛选通过 锁定3需求
           disabled: record.lockStatus === '1' || record.filterStatus === '2' || record.lockProjectCount == 3,
           onClick: handleResumeLock.bind(null, record),
          //  onClick: handlePersonAssign.bind(null, record),
         },
         {
           label: '通过',
           disabled: record.filterStatus === '1',
           onClick: handleResumePass.bind(null, record),
         },
         {
           label: '不通过',
           //筛选不通过 ||  筛选通过&&锁定 record.filterStatus === '2' || 
           //record.filterStatus === '2' || (record.filterStatus === '1' && record.lockStatus === '0'),
           disabled: record.filterStatus === '2',
           onClick: handleResumeFail.bind(null, record),
         },
         {
           label: '入场',
           disabled: record.entryStatus === '1',
           onClick: handlePersonEntry.bind(null, record),
         },
        //  {
        //    label: '面评',
        //    onClick: handleResumeEvaluate.bind(null, record),
        //  },
       ]
   }
     /**
        * 下拉操作栏
        */
  function getDropDownAction(record){
       return [
         {
           label: '编辑',
           onClick: handleEdit.bind(null, record),
         },
        //  {
        //    label: '详情',
        //    onClick: handleDetail.bind(null, record),
        //  }, 
         {
           label: '锁定需求列表',
           onClick: showLockPostionReq.bind(null, record),
         }, 
         
        //  {
        //    label: '删除',
        //    popConfirm: {
        //      title: '是否确认删除',
        //      confirm: handleDelete.bind(null, record),
        //      placement: 'topLeft',
        //    }
        //  }
       ]
   }



  /* ----------------------以下为原生查询需要添加的-------------------------- */
  const toggleSearchStatus = ref<boolean>(false);
  const labelCol = reactive({
    xs:24,
    sm:4,
    xl:6,
    xxl:4
  });
  const wrapperCol = reactive({
    xs: 24,
    sm: 20,
  });
  /**
   * 重置
   */
  function searchReset() {
    formRef.value.resetFields();
    selectedRowKeys.value = [];
    //刷新数据
    reload();
  }

</script>
<style lang="less" scoped>
  .jeecg-basic-table-form-container {
    padding: 0;
  .table-page-search-submitButtons {
    display: block;
    margin-bottom: 24px;
    white-space: nowrap;
  }
  .query-group-cust{
    min-width: 100px !important;
  }
  .query-group-split-cust{
    width: 30px;
    display: inline-block;
    text-align: center
  }
  }
</style>
